package com.ojoin.ojoin.eb_spider.queue;

import java.util.UUID;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ojoin.ojoin.eb_spider.domain.AssistCatchData;
import com.ojoin.ojoin.eb_spider.service.StatTotalService;
import com.ojoin.ojoin.eb_spider.service.impl.QueueSenderServieImpl;
import com.ojoin.ojoin.eb_spider.service.impl.SLDataCatchBaseServiceImpl;
import com.ojoin.ojoin.eb_spider.utils.SpringUtilsSpider;
import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.utils.LogUtils;
import com.ojoin.trade.supplyloan_core.web.domain.CatchDataStartMessage;
import com.ojoin.trade.supplyloan_core.web.domain.Order;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlLoanStatTotal;

/**
 * 
 * @author liang
 * @description 队列消息监听器
 * 
 */
@Scope("prototype")
@Component
public class ReceiverCatchDataTaskListener extends BaseReceiverListener{

	private static Logger log = LoggerFactory
			.getLogger(ReceiverCatchDataTaskListener.class);

	/*@Autowired
	private QueueSenderServieImpl queueSenderServie;
*/
	/*@Autowired
	@Qualifier("catchDateMessage")
	private Destination destination;*/

	@Autowired
	private StatTotalService statTotalService;
	/**
	 * 接听器名称
	 */
	private String name = UUID.randomUUID().toString();
	public void deal(Object ob) throws BusinessException, Exception {
		if (ob instanceof CatchDataStartMessage) {
			CatchDataStartMessage st = (CatchDataStartMessage) ob;

			SLDataCatchBaseServiceImpl service = SpringUtilsSpider
					.getBeanByClassName(st.getPlatformUser().getPlatformName()
							.replace("_", "")
							+ "DataCatchServiceImpl");

			AssistCatchData as = new AssistCatchData(st);
			
			service.catchData(as);

		} else if (ob instanceof Order) {
			Order st = (Order) ob;
			if (st.getOrderType().equals(Order.STATTOTAL)) {
				TbSlLoanStatTotal total = statTotalService.statTotal((Integer
						.valueOf(st.getParames().get("platformUserId"))));

				//queueSenderServie.send(destination, total);
			}
		} else {
			LogUtils.info(log, "列别不匹配");
		}
	}

}
